package controllers

import (
	"github.com/gin-gonic/gin"
	"log"
	"rongyy/src/models"
	"rongyy/src/server"
	"rongyy/src/service"
)

type OrderController struct {
	*service.OrderService
}

func NewOrderController() *OrderController {
	return &OrderController{}
}

func (rc *OrderController) create(c *gin.Context) server.IModel {
	json := &models.OrdersModel{}

	err := c.ShouldBindJSON(json)
	err = rc.Create(json)
	if err != nil {
		log.Println("decode: ", err)
	}
	if err != nil {
		return &models.DataModel{IsSuccess: false, Msg: err.Error()}
	}

	return &models.DataModel{IsSuccess: true}
}

//func (rc *OrderTrackController) queryTrackOrder(c *gin.Context) server.IModel {
//	json := &models.ReqTrack{}
//	err := c.ShouldBindJSON(json)
//	data, total, err := rc.QueryTrackOrder(json)
//	if err != nil {
//		log.Println("decode: ", err)
//	}
//	if err != nil {
//		return &models.DataModel{IsSuccess: false, Msg: err.Error()}
//	}
//
//	return &models.DataModel{IsSuccess: true, Data: map[string]interface{}{
//		"list":  data,
//		"total": total,
//	}}
//}

func (u *OrderController) RouterHandler(server *server.Server) {
	server.Handle("POST", "/create", u.create)
	//server.Handle("POST", "/query", u.queryTrackOrder)
}
